<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入理解 Reactor 线程模型</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-shadow {
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        .card-shadow:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 100%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        .first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3.5rem;
            padding-right: 8px;
            margin-top: 3px;
            font-weight: 700;
            color: #667eea;
        }
        .concept-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(102, 126, 234, 0.1);
        }
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 1rem;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            color: white;
            font-size: 24px;
            margin-bottom: 1rem;
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6">
                <i class="fas fa-network-wired mr-4"></i>
                Reactor 线程模型
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">高性能网络编程的核心设计模式</p>
            <div class="flex justify-center space-x-8 text-lg">
                <div class="flex items-center">
                    <i class="fas fa-bolt mr-2"></i>
                    <span>高并发</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-tachometer-alt mr-2"></i>
                    <span>低延迟</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-expand-arrows-alt mr-2"></i>
                    <span>可扩展</span>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction Section -->
    <section class="py-16 px-6">
        <div class="max-w-4xl mx-auto">
            <div class="bg-white rounded-2xl p-8 md:p-12 card-shadow">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="first-letter">R</span>eactor 线程模型是 Netty 和其他高性能网络框架（如 Java NIO）中广泛使用的一种设计模式，用于处理大量并发的网络连接。它通过高效地管理线程和事件，实现了高吞吐量和低延迟的网络应用。Reactor 线程模型通过高效的事件处理和线程管理，提供了一个灵活和高性能的解决方案，用于处理复杂的网络 I/O 任务。
                </p>
            </div>
        </div>
    </section>

    <!-- Core Concepts Section -->
    <section class="py-16 px-6 bg-gray-50">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-4xl font-bold mb-12 text-center text-gradient">核心概念</h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div class="concept-card rounded-2xl p-8 card-shadow">
                    <div class="feature-icon">
                        <i class="fas fa-server"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">Reactor</h3>
                    <p class="text-gray-600 leading-relaxed">
                        负责监控 I/O 事件（如连接请求、数据到达等）并将这些事件分发给相应的事件处理器。Reactor 通常运行在一个或多个线程中，处理 I/O 事件的注册、监听和分发。
                    </p>
                </div>
                <div class="concept-card rounded-2xl p-8 card-shadow">
                    <div class="feature-icon">
                        <i class="fas fa-cogs"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">Handlers</h3>
                    <p class="text-gray-600 leading-relaxed">
                        事件处理器，负责处理具体的 I/O 事件。根据事件的类型，Handlers 可能需要读取数据、写入数据或处理连接的状态等。
                    </p>
                </div>
            </div>
        </div>
    </section>

    <!-- Workflow Section -->
    <section class="py-16 px-6">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-4xl font-bold mb-12 text-center text-gradient">工作流程</h2>
            <div class="bg-white rounded-2xl p-8 card-shadow mb-12">
                <div class="mermaid">
                    graph LR
                        A[客户端请求] --> B[事件注册]
                        B --> C[事件轮询]
                        C --> D[事件分发]
                        D --> E[事件处理]
                        E --> F[响应客户端]
                        
                        style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                        style C fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style D fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                        style E fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style F fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>
            <div class="grid md:grid-cols-2 lg:grid-cols-4 gap-6">
                <div class="bg-white rounded-xl p-6 card-shadow text-center">
                    <div class="text-3xl text-purple-600 mb-4">
                        <i class="fas fa-clipboard-list"></i>
                    </div>
                    <h4 class="text-xl font-bold mb-2">事件注册</h4>
                    <p class="text-gray-600 text-sm">线程注册对特定 I/O 事件的关注，并将事件处理程序关联起来</p>
                </div>
                <div class="bg-white rounded-xl p-6 card-shadow text-center">
                    <div class="text-3xl text-purple-600 mb-4">
                        <i class="fas fa-sync-alt"></i>
                    </div>
                    <h4 class="text-xl font-bold mb-2">事件轮询</h4>
                    <p class="text-gray-600 text-sm">使用高效的 I/O 多路复用技术检测事件发生状态</p>
                </div>
                <div class="bg-white rounded-xl p-6 card-shadow text-center">
                    <div class="text-3xl text-purple-600 mb-4">
                        <i class="fas fa-share-alt"></i>
                    </div>
                    <h4 class="text-xl font-bold mb-2">事件分发</h4>
                    <p class="text-gray-600 text-sm">将检测到的事件分发给相应的处理线程</p>
                </div>
                <div class="bg-white rounded-xl p-6 card-shadow text-center">
                    <div class="text-3xl text-purple-600 mb-4">
                        <i class="fas fa-microchip"></i>
                    </div>
                    <h4 class="text-xl font-bold mb-2">事件处理</h4>
                    <p class="text-gray-600 text-sm">执行具体的 I/O 操作并更新相应状态</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Model Variants Section -->
    <section class="py-16 px-6 bg-gray-50">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-4xl font-bold mb-12 text-center text-gradient">模型变种</h2>
            <div class="grid md:grid-cols-3 gap-8">
                <div class="bg-white rounded-2xl p-8 card-shadow">
                    <div class="text-center mb-6">
                        <div class="inline-flex items-center justify-center w-20 h-20 bg-purple-100 rounded-full mb-4">
                            <i class="fas fa-user text-3xl text-purple-600"></i>
                        </div>
                        <h3 class="text-2xl font-bold mb-2">单 Reactor 单线程</h3>
                    </div>
                    <p class="text-gray-600 leading-relaxed">
                        一个 Reactor 线程处理所有的 I/O 事件和事件分发。适用于负载较轻的应用，通过单线程简单处理所有事件。
                    </p>
                    <div class="mt-6 pt-6 border-t border-gray-200">
                        <div class="flex items-center text-sm text-gray-500">
                            <i class="fas fa-check-circle text-green-500 mr-2"></i>
                            简单实现
                        </div>
                        <div class="flex items-center text-sm text-gray-500 mt-2">
                            <i class="fas fa-times-circle text-red-500 mr-2"></i>
                            性能受限
                        </div>
                    </div>
                </div>
                <div class="bg-white rounded-2xl p-8 card-shadow">
                    <div class="text-center mb-6">
                        <div class="inline-flex items-center justify-center w-20 h-20 bg-purple-100 rounded-full mb-4">
                            <i class="fas fa-users text-3xl text-purple-600"></i>
                        </div>
                        <h3 class="text-2xl font-bold mb-2">单 Reactor 多线程</h3>
                    </div>
                    <p class="text-gray-600 leading-relaxed">
                        一个 Reactor 线程负责事件轮询和分发，多个工作线程处理具体的 I/O 事件。可处理更高负载，提高吞吐量。
                    </p>
                    <div class="mt-6 pt-6 border-t border-gray-200">
                        <div class="flex items-center text-sm text-gray-500">
                            <i class="fas fa-check-circle text-green-500 mr-2"></i>
                            更高吞吐量
                        </div>
                        <div class="flex items-center text-sm text-gray-500 mt-2">
                            <i class="fas fa-check-circle text-green-500 mr-2"></i>
                            充分利用多核
                        </div>
                    </div>
                </div>
                <div class="bg-white rounded-2xl p-8 card-shadow">
                    <div class="text-center mb-6">
                        <div class="inline-flex items-center justify-center w-20 h-20 bg-purple-100 rounded-full mb-4">
                            <i class="fas fa-project-diagram text-3xl text-purple-600"></i>
                        </div>
                        <h3 class="text-